package com.newlink.building.secret.mvp.presenter

import com.newlink.building.common_base.base.BasePresenter
import com.newlink.building.common_base.ext.ss
import com.newlink.building.common_base.model.bean.DeviceListRequest
import com.newlink.building.common_base.model.bean.SecretKeyAddRequest
import com.newlink.building.common_base.model.bean.StatusData
import com.newlink.building.secret.mvp.contract.Module_Secret_SecretKeyAddContract
import com.newlink.building.secret.mvp.model.Module_Secret_SecretKeyAddModel

/**
 * Created by xiaodong on 2022/10/2.
 */
class Module_Secret_SecretKeyAddPresenter :
    BasePresenter<Module_Secret_SecretKeyAddContract.Model, Module_Secret_SecretKeyAddContract.View>(),
    Module_Secret_SecretKeyAddContract.Presenter {
    override fun createModel(): Module_Secret_SecretKeyAddContract.Model = Module_Secret_SecretKeyAddModel()

    override fun addSecretKey(requestBean: SecretKeyAddRequest) {
        mView?.showLoading()
        mModel?.addSecretKey(requestBean)?.ss(mModel, mView, false) { result ->
            mView?.hideLoading()
            if (result?.code == 200) {
                mView?.refreshAddStatus(StatusData(true))
            }
        }
    }

    override fun getDeviceList(requestBean: DeviceListRequest) {
        mView?.showLoading()
        mModel?.getDeviceList(requestBean)?.ss(mModel, mView) { result ->
            if (result?.data != null) {
                result.data.list?.let { mView?.refreshDeviceList(it) }
            }
        }
    }
}